<?PHP

$email = $_POST['email'];
$password = $_POST['password'];
$name = $_POST['name'];
$school = $_POST['school'];
$taxpayer_identification_number = $_POST['taxpayer_identification_number'];
$invoice_title = $_POST['invoice_title'];
$single_rooms = $_POST['single_rooms'];
$standard_rooms = $_POST['standard_rooms'];
$meeting_datetime = $_POST['meeting_date'] . ' '.$_POST['meeting_time'];
$leave_datetime = $_POST['leave_date'] . ' '.$_POST['leave_time'];
$halal_foods = $_POST['halal_foods'];

if(!empty($_GET['flag'])){$flag=$_GET['flag'];}else{$flag='';}



$mysqli = mysqli_init();

$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); //设置超时时间
$mysqli->real_connect('127.0.0.1', 'root', 'mysql');
$sql = "CREATE DATABASE IF NOT EXISTS CUPT DEFAULT CHARSET utf8 COLLATE utf8_general_ci;";
if ($mysqli->query($sql) == TRUE) {
    //printf("Table CUPT successfully created.\n");
}
mysqli_select_db($mysqli, "CUPT");
/*//建表
$sql = "CREATE TABLE IF NOT EXISTS `school_information_list` (
        `email` varchar(20) DEFAULT NULL,
        `name` varchar(20) DEFAULT NULL,
        `school` varchar(40) DEFAULT NULL,  
        `taxpayer_identification_number` varchar(35) DEFAULT NULL,
        `single_rooms` varchar(4) DEFAULT NULL,
        `standard_rooms` varchar(4) DEFAULT NULL,
        `meeting_datetime` varchar(30) DEFAULT NULL,
        `leave_datetime` varchar(30) DEFAULT NULL,
        `halal_foods` varchar(4) DEFAULT NULL,
        `school_number` varchar(3) DEFAULT NULL,
        UNIQUE KEY(`school`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";

if (mysqli_query($mysqli, $sql)) {
    //echo "数据表 participant 创建成功";
} else {
    //echo "创建数据表错误: " . mysqli_error($mysqli);
}*/

$sql = "select * from participant where `email`='$email' and `password`='$password' and `school`='$school';";
$rst = $mysqli->query($sql);
$sql2 = "select email from school_information_list where`school`='$school';";
$rst2 = $mysqli->query($sql2);
if ($rst->num_rows == 0) {
    echo "<br />邮箱、密码或学校填写错误<br />";
    echo '<a href="javascript :;" onClick="javascript :history.back(-1);">回到学校注册界面</a>';
} elseif(mysqli_fetch_assoc($rst2)['email']!= ''&&$flag==0){
    echo "<br />学校已注册<br />";
    echo '如需修改注册信息请<a href="javascript :;" onClick="javascript :history.back(-1);">回到学校注册界面</a>，并点击“修改学校注册信息”按钮';
}
else {
//插入数据
    if($flag==0)
    {
    $sql = "UPDATE school_information_list SET email='$email',name ='$name',taxpayer_identification_number='$taxpayer_identification_number',invoice_title='$invoice_title',single_rooms='$single_rooms',standard_rooms='$standard_rooms',meeting_datetime='$meeting_datetime', leave_datetime='$leave_datetime',halal_foods='$halal_foods' WHERE school = '$school';";
    $mysqli->query($sql);
    echo "<br />学校注册成功<br />";
    mysqli_close($mysqli);
    }
    else{
    $sql = "UPDATE school_information_list SET email='$email',name ='$name',taxpayer_identification_number='$taxpayer_identification_number',invoice_title='$invoice_title',single_rooms='$single_rooms',standard_rooms='$standard_rooms',meeting_datetime='$meeting_datetime', leave_datetime='$leave_datetime',halal_foods='$halal_foods' WHERE school = '$school';";
    $mysqli->query($sql);
    echo "<br />学校信息修改成功<br />";
    mysqli_close($mysqli);
    }
    //echo $school_logo;
    
}



?>